#include "circleprogressbar.h"
#include "ui_circleprogressbar.h"
#include <QPainter>

CircleProgressBar::CircleProgressBar(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::CircleProgressBar)
{
    ui->setupUi(this);
}

CircleProgressBar::~CircleProgressBar()
{
    delete ui;
}

void CircleProgressBar::paintEvent(QPaintEvent *event) {
    Q_UNUSED(event);
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);

    // 绘制背景圆
    painter.setPen(Qt::gray);
    painter.drawEllipse(rect().adjusted(5,5,-5,-5));

    // 绘制进度弧
    QPen progressPen(m_progressColor, 8);
    painter.setPen(progressPen);
    int spanAngle = m_value * 360 / 100;  // 按百分比计算角度
    painter.drawArc(rect().adjusted(10,10,-10,-10), 90*16, -spanAngle*16);
}

void CircleProgressBar::setValue(int val) {
    m_value = qBound(0, val, 100);
    update();
}
